
(defun eshell-setting ()
  
  (outline-minor-mode)
  (cscope-minor-mode)
  (setq outline-regexp "^[^#$\n]* [#>]+ "
        scroll-margin 0
        eshell-scroll-to-bottom-on-output t
        eshell-history-size 256
        eshell-hist-ignoredups t
        eshell-show-maximum-output t)

  (defvar eshell-path-alist
    `(("e" . "~/.emacs.d/")
      ("hpdvr" . "/gm/hpdvr")
      ("gipnc" . "/gm/gm813x_better")
      ("hipnc" . "/hi/ipnc")
      ("tipnc" . "/ti/dm36x/ipnc")))

  (defun eshell/d (args)
    (let ((path (cdr (assoc args eshell-path-alist))))
      (eshell/cd path)))
  (defun pcomplete/d ()
    (pcomplete-here
     (mapcar #'car eshell-path-alist)))

  (defun eshell/w (&rest args)
    (interactive "P")
    (when *cygwin*
      (if args
          (shell-command (format "cygstart %s" (car args)))
        (shell-command "cygstart ."))))

  (setq eshell-command-aliases-list
        (append eshell-command-aliases-list
                '(("de" "cd ~/.emacs.d")
                  ("ww" "cygstart")
                  ("hm" "helm-bookmarks")
                  ("ht" "helm-top")
                  ("b" "ido-swith-buffer")
                  ("bb" "back-to-previous-buffer")
                  ("xb" "ido-switch-buffer")
                  ("xbb" "ibuffer")
                  ("hf" "helm-for-files")
                  ("cf" "helm-for-files")
                  ("hr" "helm-recentf")
                  ("he" "helm-resume nil")
                  ("d1" "cd ..")
                  ("d2" "cd ...")
                  ("d3" "cd ....")
                  ("d4" "cd .....")
                  ("xf" "ido-find-file")
                  ("eh" "helm-eshell-history")
                  ("xd" "ido-dired")
                  ("dum" "du -ah --max-depth=1")
                  ("ff" "ido-find-file")
                  ("csn" "cscope-history-forward-line-current-result")
                  ("csp" "cscope-history-backward-line-current-result")
                  ("csd" "helm-cscope-find-global-definition")
                  ("csc" "helm-cscope-find-calling-this-funtcion")
                  ("csC" "helm-cscope-find-called-function")
                  ("cst" "helm-cscope-find-this-text-string")
                  ("csf" "helm-cscope-find-this-file")
                  ("css" "helm-cscope-find-this-symbol")
                  ("cse" "helm-cscope-find-egrep-pattern")
                  ("csb" "helm-cscope-display-buffer")
                  ("csi" "helm-cscope-find-files-including-file")
                  ("csu" "helm-cscope-pop-mark")
                  )))

  (add-to-list 'eshell-output-filter-functions
               'eshell-postoutput-scroll-to-bottom))

(add-hook 'eshell-mode-hook 'eshell-setting)

(add-hook 'emacs-startup-hook #'(lambda () 
                                  (command-execute 'eshell)))

(global-set-key (kbd "<f5>") 'eshell)

(provide 'init-eshell)
